package com.eva.admin.api.cms;

import com.eva.admin.biz.cms.article.CmsArticleTagBiz;
import com.eva.admin.biz.cms.article.dto.CreateCmsArticleTagDTO;
import com.eva.admin.biz.cms.article.dto.QueryCmsArticleTagDTO;
import com.eva.admin.biz.cms.article.dto.UpdateCmsArticleTagDTO;
import com.eva.admin.biz.cms.article.vo.CmsArticleTagVO;
import com.eva.dao.cms.model.CmsArticleTag;
import com.eva.framework.common.api.BaseController;
import com.eva.framework.rbac.authorize.ContainPermissions;
import com.eva.framework.security.prevent.PreventRepeat;
import com.eva.framework.common.model.ApiResponse;
import com.eva.framework.common.model.PageData;
import com.eva.framework.common.model.PageWrap;
import com.eva.service.cms.CmsArticleTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "文章标签")
@RestController
@RequestMapping("/cms/article/tag")
public class CmsArticleTagController extends BaseController {

    @Resource
    private CmsArticleTagBiz cmsArticleTagBiz;

    @Resource
    private CmsArticleTagService cmsArticleTagService;

    @PreventRepeat
    @ApiOperation("新建")
    @PostMapping("/create")
    @ContainPermissions("cms:article:tag:create")
    public ApiResponse<?> create(@RequestBody CreateCmsArticleTagDTO dto) {
        cmsArticleTagBiz.create(dto);
        return ApiResponse.success(null);
    }

    @ApiOperation("删除")
    @GetMapping("/delete/{id}")
    @ContainPermissions("cms:article:tag:delete")
    public ApiResponse<?> deleteById(@PathVariable Integer id) {
        cmsArticleTagBiz.deleteById(id);
        return ApiResponse.success(null);
    }

    @ApiOperation("批量删除")
    @GetMapping("/delete/batch")
    @ContainPermissions("cms:article:tag:delete")
    public ApiResponse<?> deleteByIdInBatch(@RequestParam String ids) {
        cmsArticleTagBiz.deleteByIdInBatch(this.getIdList(ids));
        return ApiResponse.success(null);
    }

    @ApiOperation("修改")
    @PostMapping("/updateById")
    @ContainPermissions("cms:article:tag:update")
    public ApiResponse<?> updateById(@RequestBody UpdateCmsArticleTagDTO dto) {
        cmsArticleTagBiz.updateById(dto);
        return ApiResponse.success(null);
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    @ContainPermissions("cms:article:tag:query")
    public ApiResponse<PageData<CmsArticleTagVO>> findPage (@RequestBody PageWrap<QueryCmsArticleTagDTO> pageWrap) {
        return ApiResponse.success(cmsArticleTagBiz.findPage(pageWrap));
    }

    @ApiOperation("查询所有")
    @GetMapping("/all")
    public ApiResponse<List<CmsArticleTag>> findAll () {
        return ApiResponse.success(cmsArticleTagService.findAll());
    }
}
